package com.ruoyi.edit.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edit.domain.VendorCourseRelPackagev2;
import com.ruoyi.edit.service.IVendorCourseRelPackagev2Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程教保指引关联Controller
 * 
 * @author qiufeng
 * @date 2022-12-15
 */
@Controller
@RequestMapping("/system/vendorCourseRelPackagev2")
public class VendorCourseRelPackagev2Controller extends BaseController
{
    private String prefix = "system/vendorCourseRelPackagev2";

    @Autowired
    private IVendorCourseRelPackagev2Service vendorCourseRelPackagev2Service;

    @GetMapping()
    public String vendorCourseRelPackagev2()
    {
        return prefix + "/vendorCourseRelPackagev2";
    }


    @GetMapping("/packageV2Id")
    public String packageV2Id(String packageV2Id, ModelMap mmap)
    {
        mmap.put("packageV2Id", packageV2Id);
        return prefix + "/vendorCourseRelPackagev2";
    }
    /**
     * 查询课程教保指引关联列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        startPage();
        List<VendorCourseRelPackagev2> list = vendorCourseRelPackagev2Service.selectVendorCourseRelPackagev2List(vendorCourseRelPackagev2);
        return getDataTable(list);
    }

    /**
     * 导出课程教保指引关联列表
     */
    @Log(title = "课程教保指引关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        List<VendorCourseRelPackagev2> list = vendorCourseRelPackagev2Service.selectVendorCourseRelPackagev2List(vendorCourseRelPackagev2);
        ExcelUtil<VendorCourseRelPackagev2> util = new ExcelUtil<VendorCourseRelPackagev2>(VendorCourseRelPackagev2.class);
        return util.exportExcel(list, "课程教保指引关联数据");
    }

    /**
     * 新增课程教保指引关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程教保指引关联
     */
    @Log(title = "课程教保指引关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        return toAjax(vendorCourseRelPackagev2Service.insertVendorCourseRelPackagev2(vendorCourseRelPackagev2));
    }

    /**
     * 修改课程教保指引关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        VendorCourseRelPackagev2 vendorCourseRelPackagev2 = vendorCourseRelPackagev2Service.selectVendorCourseRelPackagev2ById(id);
        mmap.put("vendorCourseRelPackagev2", vendorCourseRelPackagev2);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程教保指引关联
     */
    @Log(title = "课程教保指引关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VendorCourseRelPackagev2 vendorCourseRelPackagev2)
    {
        return toAjax(vendorCourseRelPackagev2Service.updateVendorCourseRelPackagev2(vendorCourseRelPackagev2));
    }

    /**
     * 删除课程教保指引关联
     */
    @Log(title = "课程教保指引关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vendorCourseRelPackagev2Service.deleteVendorCourseRelPackagev2ByIds(ids));
    }


    @GetMapping("/getIds")
    public String getIds(String courseId, ModelMap mmap)
    {
        VendorCourseRelPackagev2 vendorCourseRelPackagev2 = new VendorCourseRelPackagev2();
        vendorCourseRelPackagev2.setVendorCourseId(courseId);
        List<VendorCourseRelPackagev2> list = vendorCourseRelPackagev2Service.selectVendorCourseRelPackagev2List(vendorCourseRelPackagev2);
        List<String> stringList = list.stream().map(k -> k.getPackageV2Id()).collect(Collectors.toList());
        String ids = StringUtils.join(stringList,",");
        mmap.put("ids", ids);
        return "system/coursePackageV2/coursePackageV2_1";
    }
}
